/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.dataaccess.hibernate;

import cms.dataaccess.PaymentDAO;
import cms.exceptions.HibernateAccessLayerException;
import dto.Payment;
import java.util.List;

/**
 *
 * @author WU DAO BO
 */
public class PaymentDAOImpl extends AbstractDAO implements PaymentDAO {

   public PaymentDAOImpl(){
        super();
    }
    @Override
    public void insertPayment(Payment pay) throws HibernateAccessLayerException  {
     try {  
           this.saveOrUpdate(pay);
          } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public void deletePayment(Payment pay) throws HibernateAccessLayerException  {
         try {  
           this.delete(pay);
          } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public void updatePayment(Payment pay)  throws HibernateAccessLayerException  {
         try {  
           this.saveOrUpdate(pay);
          } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public Payment findPayment(String userName, String payName, int type) throws HibernateAccessLayerException  {
         try {  
             String queryString = "userName='" + userName +"' and payName='"+payName+"' and payType="+type;
             return  (Payment) super.findByCustomizeQuery(Payment.class, queryString).get(0);
          } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public List<Payment> findPayment(String userName) throws HibernateAccessLayerException  {
            try {  
             String queryString = "userName='" + userName;
             return  (List<Payment>) (super.findByCustomizeQuery(Payment.class, queryString));
          } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public List<Payment> findPayment(String userName, int type)  throws HibernateAccessLayerException {
           try {  
             String queryString = "userName='" + userName +"' and payType="+type;
             return (List<Payment>)(super.findByCustomizeQuery(Payment.class, queryString));
          } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public List<Payment> findPaymentByApprover(String appover) throws HibernateAccessLayerException  {
         try {  
             String queryString = "appover='" + appover +"' ";
             return (List<Payment>)(super.findByCustomizeQuery(Payment.class, queryString));
          } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public List<Payment> findPaymentByStatus(String status) throws HibernateAccessLayerException  {
          try {  
             String queryString = "payStatus='" + status +"' ";
             return (List<Payment>)(super.findByCustomizeQuery(Payment.class, queryString));
          } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public List<Payment> findAllPayment() throws HibernateAccessLayerException {
        try {  
          return this.findAll(Payment.class);
          } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }    
    }

    @Override
    public List<Payment> findAllPayment(int type) throws HibernateAccessLayerException {
        try {  
          return this.findByCustomizeQuery(Payment.class, "payType="+type);
          } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }    
    }

    @Override
    public List<Payment> findPaymentPayName(String payName, int type) throws HibernateAccessLayerException {
            try {  
             return this.findByCustomizeQuery(Payment.class, "payName='"+payName+"'and  payType="+type);
            } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        } 
    }





    
}
